package com.mune.gulimall.search.controller;

import com.mune.gulimall.search.service.MallSearchService;
import com.mune.gulimall.search.vo.SearchParam;
import com.mune.gulimall.search.vo.SearchResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
public class searchController {
  @Autowired
  MallSearchService mallSearchService;

  @GetMapping("/list.html")
  public String listPage(SearchParam searchParam, Model model, HttpServletRequest servletRequest) {
    searchParam.set_queryString(servletRequest.getQueryString());
    // 根据传递过来的参数，去es中进行检索
    SearchResult result = mallSearchService.search(searchParam);
    model.addAttribute("result", result);
    return "list";
  }
}
